myApp.controller('PushRecordController',function($scope,$http){
    initPage();

    function initPage(){
        $scope.pushRecordList = [];
        $scope.count = 0;

        
        $scope.total=$scope.pushRecordList.length;
        console.log($scope.total);

        $scope.page = {size: 10, index: 1}; 


        $http.post(java_url+'/beetle/pushRecord/getPushRecordList',{
            tokenId:getTokenId()
        }).success(function(data){
            if(data.code == '0'){
                $scope.count = data.data.count;
                if(data.data.count == 0){
                    return;
                }else{
                    $scope.pushRecordList = data.data.list;
                    for(var i=0;i<$scope.pushRecordList.length;i++){
                        var status = $scope.pushRecordList[i].status;
                        if(status == '0'){
                            $scope.pushRecordList[i].statusDesc = "推送成功";
                        }else if(status == '1'){
                            $scope.pushRecordList[i].statusDesc = "推送失败";
                        }else if(status == '2'){
                            $scope.pushRecordList[i].statusDesc = "推送中";
                        }else if(status == '3'){
                            $scope.pushRecordList[i].statusDesc = "推送未开始";
                        }else{
                            $scope.pushRecordList[i].statusDesc = "";
                        };
                    };

                    return;
                };
            }else if(data.code == '2'){
                window.location.href = "/beetle/App/module/login/tpl/login.html";
                return;
            }else{
                alert(data.desc);
                return;
            };
        });
    };

    // $scope.pageChanged = function() {
    //     $scope.showRecordList = [];
    //     for(var i=($scope.currentPage-1)*$scope.itemsPerPage;i<($scope.currentPage*$scope.itemsPerPage > $scope.count?$scope.count:$scope.currentPage*$scope.itemsPerPage);i++){
    //         $scope.showRecordList.push($scope.pushRecordList[i]);
    //     };
    // };

    $scope.repush = function (recordName) {
        $http.post(java_url+'/beetle/pushRecord/restartPush',{
            recordName:recordName,
            tokenId:getTokenId()
        }).success(function(data){
            alert(data.desc);
            initPage();
        });
    };
});